package cn.mickey.exchange.domain;

import java.io.Serializable;

public class JsonResponse<T> implements Serializable {

    private Integer code;

    private String msg;

    private T data;

    public JsonResponse() {
    }

    public JsonResponse(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public JsonResponse(T data){
        this.data = data;
        msg = "成功";
        code = 1;
    }

    public JsonResponse(T data,Integer code,String msg){
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    public static JsonResponse<String> success(){
        return new JsonResponse<>(1,"成功");
    }

    public static <T>JsonResponse success(T data){
        return new JsonResponse<>(data);
    }

    public static JsonResponse<String> success(String msg){
        return new JsonResponse<>(1,msg);
    }

    public static JsonResponse<String> fail(){
        return new JsonResponse<>(0, "失败");
    }

    public static JsonResponse<String> fail(Integer code, String msg){
        return new JsonResponse<>(code, msg);
    }

    public static JsonResponse<String> fail( String msg){
        return new JsonResponse<>(0, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
